package cn.tedu.cwgl.controller;

import cn.tedu.cwgl.entity.Insurance;
import cn.tedu.cwgl.service.InsuService;
import cn.tedu.cwgl.util.PageModel;
import cn.tedu.cwgl.util.Result;
import cn.tedu.cwgl.util.ResultUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;


@RequestMapping("/insurance")
@Controller
public class InsuController {


    @Resource
    private InsuService insuService;


    @RequestMapping("/getInsurance/{pageNo}/{pageSize}")
    @ResponseBody
    public Result<Insurance> getInsurance(Insurance insurance, @PathVariable int pageNo, @PathVariable int pageSize) {
        PageModel model = new PageModel<>(pageNo, insurance);
        model.setPageSize(pageSize);
        return insuService.getInsurance(model);
    }

    @RequestMapping("/addInsurance")
    @ResponseBody
    public Result addInsurance(Insurance insurance, HttpSession session) {
        int result = insuService.addInsurance(insurance, session);
        if (result > 0) {
            return ResultUtil.success();
        } else {
            return ResultUtil.unSuccess();
        }
    }

    @RequestMapping("/delInsurance")
    @ResponseBody
    public Result delInsurance(Insurance insurance, HttpSession session) {

        int result = insuService.delInsurance(insurance, session);
        if (result > 0) {
            return ResultUtil.success();
        } else {
            return ResultUtil.unSuccess();
        }

    }

    @RequestMapping("/updateInsurance")
    @ResponseBody
    public Result updateInsurance(Insurance insurance, HttpSession session) {

        int result = insuService.updateInsurance(insurance, session);
        if (result > 0) {
            return ResultUtil.success();
        } else {
            return ResultUtil.unSuccess();
        }

    }

}
